package com.zimmor.mq.rocket.banch;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author:zimmor
 * @Date: 2021/11/18 14:34
 * @Description 发送同步消息
 * @version: 1.0.0
 */

public class Producer {
    public static void main(String[] args) throws Exception {
       //发送消息的步骤
       //1.创建一个producer 设置producer的生产者组名groupID，
        DefaultMQProducer producer = new DefaultMQProducer("group4");
        //2.设置namesrv地址
        producer.setNamesrvAddr("192.168.204.50:9876");
       //3.启动producer
        producer.start();

        String topic = "banchTopic";
        List<Message> messages = new ArrayList<Message>();
        messages.add(new Message(topic, "tag", "OrderID001", "Hello world 0".getBytes()));
        messages.add(new Message(topic, "tag1", "OrderID002", "Hello world 1".getBytes()));
        messages.add(new Message(topic, "tag1", "OrderID003", "Hello world 2".getBytes()));
        producer.send(messages);
       //6.关闭producer
        producer.shutdown();
    }
}
